/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bookshop.managedBean;

import com.bookshop.controllers.util.JsfUtil;
import com.bookshop.entity.Customer;
import com.bookshop.service.CustomerService;
import com.bookshop.util.NavigationHelper;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

/**
 *
 * @author Thibault
 */
public class CustomerManagedBean {

    @EJB
    private CustomerService customerService;
    
    //@ManagedProperty("#{securityManagedBean}")
    private SecurityManagedBean securityManagedBean; 
    
    private Customer customer = new Customer();

    public SecurityManagedBean getSecurityManagedBean() {
        return securityManagedBean;
    }

    public void setSecurityManagedBean(SecurityManagedBean securityManagedBean) {
        this.securityManagedBean = securityManagedBean;
    }

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    /**
     * Creates a new instance of CustomerManagedBean
     */
    public CustomerManagedBean() {
        
    }
        
    public String registerClickEvent() {
        customerService.createCustomer(customer);
        customer = new Customer();
        return "toLogIn";
    }
    
    public String connexionClick() {
        if (customer.getLogin() != null && customer.getPassword() != null) {
            return securityManagedBean.logInClickEvent(customer.getLogin(), customer.getPassword());
        }
        return "toLogIn";
    }
    
    public String disconnectClick() {
        return securityManagedBean.logOutClickEvent();
    }
    
    public void mySpaceClickEvent(ActionEvent actionEvent) {
        FacesContext context = FacesContext.getCurrentInstance();
        
        context.addMessage(null, new FacesMessage("Mon espace", "Mon espace en cours de réalisation"));
    }
    
}
